using System;
using System.Data;
using System.Configuration;
using System.Web;


using IBatisNet.Common.Utilities;
using IBatisNet.DataMapper;
using IBatisNet.DataMapper.Configuration;
using System.Xml;
using System.Reflection;
using System.IO;

/// <summary>
/// Summary description for Mapper
/// </summary>
/// 
namespace FSS.DAL.DBManagers
{
    public class Mapper
    {
        private static volatile ISqlMapper _mapper = null;
        private static volatile ISqlMapper _mapperSQL = null;
        protected static void Configure(object obj)
        {
            _mapper = null;
        }

        protected static void InitMapper()
        {
            /* ConfigureHandler handler = new ConfigureHandler(Configure);
             DomSqlMapBuilder builder = new DomSqlMapBuilder();
             _mapper = builder.ConfigureAndWatch(handler);*/
            DomSqlMapBuilder builder = new DomSqlMapBuilder();
            XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument("SqlMapSQL.config,FSS.DAL");
            _mapper = builder.Configure(sqlMapConfig);

        }
        protected static void InitMapperSQL()
        {
            /* ConfigureHandler handler = new ConfigureHandler(Configure);
             DomSqlMapBuilder builder = new DomSqlMapBuilder();
             _mapper = builder.ConfigureAndWatch(handler);*/
            DomSqlMapBuilder builderSQL = new DomSqlMapBuilder();
            XmlDocument sqlMapConfigSQL = Resources.GetEmbeddedResourceAsXmlDocument("SqlMapSQL.config,FSS.DAL");
            _mapperSQL = builderSQL.Configure(sqlMapConfigSQL);
        }

        public static ISqlMapper Instance()
        {
            if (_mapper == null)
            {
                lock (typeof(SqlMapper))
                {
                    if (_mapper == null) // double-check
                    {
                        InitMapper();
                    }
                }
            }
            return _mapper;
        }
        public static ISqlMapper InstanceSQL()
        {
            if (_mapperSQL == null)
            {
                lock (typeof(SqlMapper))
                {
                    if (_mapperSQL == null) // double-check
                    {
                        InitMapperSQL();
                    }
                }
            }
            return _mapperSQL;
        }

        public static ISqlMapper Get()
        {
            return Instance();
        }
        public static ISqlMapper GetSQL()
        {
            return InstanceSQL();
        }

    }
}